<?php
/**
 * Author: ChenGuangHui
 * Email：13035809409@163.com
 * Date Time: 2021/9/22 15:49
 */


namespace App\Models\Order;


use App\Models\Model;
use App\Models\User;

/**
 * App\Models\Order\Refund
 *
 * @property int $id
 * @property int $order_id 订单ID
 * @property int $uid 用户id
 * @property string $order_no 订单号
 * @property string $status 订单状态[1、待处理，2、处理中，3、处理完成]
 * @property string $contact 收货人
 * @property string $moblie 手机号码
 * @property string|null $shipping_name 物流名称
 * @property string|null $shipping_code 物流单号
 * @property string|null $post_fee 邮费
 * @property string $remark 备注
 * @property \Illuminate\Support\Carbon|null $created_at 创建时间
 * @property \Illuminate\Support\Carbon|null $updated_at 更新时间
 * @property-read mixed $status_name
 * @property-read User|null $user
 * @method static \Illuminate\Database\Eloquent\Builder|Refund newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Refund newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Refund query()
 * @method static \Illuminate\Database\Eloquent\Builder|Refund whereContact($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Refund whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Refund whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Refund whereMoblie($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Refund whereOrderId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Refund whereOrderNo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Refund wherePostFee($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Refund whereRemark($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Refund whereShippingCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Refund whereShippingName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Refund whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Refund whereUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Refund whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class Refund extends Model
{
    protected $connection = 'store';
    
    protected $table = 'store_order_refund';

    protected $primaryKey = 'id';

    protected $appends = ['status_name'];

    // 订单状态[1、售后申请，2、售后处理中，3、售后完成]
    const WAIT_PAID_ORDER = 1;
    const SUCCESS_PAID_ORDER = 2;
    const WAIT_SHIPPED_ORDER = 3;

     // 订单状态
     public static $status = [
        self::WAIT_PAID_ORDER         =>      '未付款',
        self::SUCCESS_PAID_ORDER      =>      '已付款',
        self::WAIT_SHIPPED_ORDER      =>      '未发货',
    ];

    /**
     * @author ChenGuangHui
     * @dateTime 2022-05-07
     */
    public function getStatusNameAttribute()
    {
        return isset($this->attributes['status']) ? self::$status[$this->attributes['status']] : '待处理';
    }

    public function user()
    {
        return $this->hasOne(User::class, 'uid', 'uid');
    }
}

